<?php

namespace admin\modules\rbac\controllers;


use admin\modules\rbac\forms\MenuRole;
use yii\web\Controller;

/**
 * MenuController implements the CRUD actions for Menu model.
 */
class MenuController extends Controller
{
    public function actionIndex()
    {
        return $this->render('index');
    }

    /**
     * @param $menu_id
     * @return string|\yii\web\Response
     * @throws \yii\db\Exception
     */
    public function actionAllotRole($menu_id)
    {
        $model = new MenuRole();
        $model->menu_id = $menu_id;
        $model->roles = $model->getMenuCheckedInAllRoles();
        $model->menu_roles = $model->menuRoles;
        if ($model->load(\Yii::$app->request->post())&&$model->validate()){
            if ($model->saveMenuRoles()){
                return $this->redirect(['allot-role', 'menu_id' => $menu_id]);
            }
        }
        return $this->render('allot-role', [
            'model' => $model,
        ]);
    }
}
